$(document).ready(function() {
    
    
    $('#st_start_date').datepicker({
            format: "yyyy-mm-dd",
            autoclose: true,
            todayHighlight: true
     });
 
    $('#st_end_date').datepicker({
            format: "yyyy-mm-dd",
            autoclose: true,
            todayHighlight: true
     });
      $('.st_all_type').hide();
      
      
      
     $('#st_type').change(function(){
         var st_type = $(this).val();
         if(st_type == 'sold'){
            var prp_saleprice = $("#prp_saleprice").val();
            var vat_value = $("#vat_value").val();
            $('#st_price').val(prp_saleprice);
            var vat_per = (parseInt(prp_saleprice) * parseInt(vat_value) )/100;
            $("#vat").val(vat_per);
            var total_value = parseInt(vat_per) + parseInt(prp_saleprice);
           
            $("#total_price").val(total_value);
                
                
            $('.sold').show();
            $('.st_price').show();
            $('.rent').hide();
         }else if(st_type == 'rented'){
            var prp_rentprice = $("#prp_rentprice").val();
            $('#st_price').val(prp_rentprice);
            var vat_value = $("#vat_value").val();
            var vat_per = (parseInt(prp_rentprice) * parseInt(vat_value) )/ 100;
            var total_value = parseInt(vat_per) + parseInt(prp_rentprice);
            $("#vat").val(vat_per);
            $("#total_price").val(total_value);
                
            
            $('.rent').show();
            $('.st_price').show();
            $('.sold').hide();
         }else{
             $('.st_all_type').hide();
         }
     });
    
     $("#agent_id").select2();
     $("#referral_name").select2();
     
     
     $('#st_price').change(function(){
        var st_price = $(this).val();
        var vat_rate = $("#vat_rate").val();
        var postdata = {};
            postdata['vat_rate'] = vat_rate;
            postdata['st_price'] = st_price;
            jQuery.post(BASE_PATH + '/status/getvatvalue', postdata, function(result) {
               
                $("#vat").val(result); 
                var total_value = parseInt(result) + parseInt(st_price);
                $("#total_price").val(total_value);
            });
     });
     
     $('#vat_rate').change(function(){
        var vat_rate = $(this).val();
        var st_price = $("#st_price").val();
        //var vat = (st_price * vat_rate)/100;;
          var postdata = {};
            postdata['vat_rate'] = vat_rate;
            postdata['st_price'] = st_price;
            jQuery.post(BASE_PATH + '/status/getvatvalue', postdata, function(result) {
               
                $("#vat").val(result); 
                var total_value = parseInt(result) + parseInt(st_price);
                $("#total_price").val(total_value);
            });
     });
    
    
    
    //show client datepicker and note 
    if($("#sold_status").val() == 1 ){
        $('.sold').show();
        $('.st_price').show();
        $('.rent').hide();
    }
    if($("#rent_status").val() == 1 ){
        $('.rent').show();
        $('.st_price').show();
        $('.sold').hide();
    }
     
});
	 